package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessWallet;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.widget.EditTextWithClear;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2018/10/9 20:00
 * 修改备注：
 * ================================================
 */
public class AddBankActivity extends BaseActivity {

    @Bind(R.id.et_name)
    EditTextWithClear etName;
    @Bind(R.id.et_card_name)
    EditTextWithClear etCardName;
    @Bind(R.id.et_branch_name)
    EditTextWithClear etBranchName;
    @Bind(R.id.et_number)
    EditTextWithClear etNumber;
    @Bind(R.id.bt_add)
    Button btAdd;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_add_bank);
        setTitle("新增银行卡");
    }

    @Override
    public void initMember() {

    }

    @Override
    public void addListener() {
        btAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = etName.getText().toString();
                String cardName = etCardName.getText().toString();
                String branchName = etBranchName.getText().toString();
                String number = etNumber.getText().toString();
                BusinessWallet.addBankCard(AddBankActivity.this, name, cardName, number, branchName, mHandler);
            }
        });
    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);

                switch (msg.what) {
                    case MSG.MSG_ADD_BANK_CARD_SUCCESS:
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_ADD_BANK_CARD_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    @Override
    public void callBack(Object object) {
        showToast("添加成功");
        setResult(RESULT_OK);
        finish();
    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
